package com.zzyl.controller;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingPlanDto;
import com.zzyl.entity.NursingPlan;
import com.zzyl.service.NursingPlanService;
import com.zzyl.vo.NursingPlanVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController()
@RequestMapping("nursing/plan")
@Api(tags = "护理计划相关接口")
public class NursingPlanController  extends BaseController{
    @Autowired
    private NursingPlanService nursingPlanService;


    /**
     * 分页查询
     * @param name
     * @param status
     * @param pageNum
     * @param pageSize
     * @return
     */
    @GetMapping("/search")
    @ApiOperation("分页查询护理计划列表")
    public ResponseResult<PageResponse<NursingPlanVo>> pageQuer(
            @ApiParam(value = "护理项目名称")
            @RequestParam(value = "name", required = false) String name,
            @ApiParam(value = "状态：0-禁用，1-启用")
            @RequestParam(value = "status", required = false) Integer status,
            @ApiParam(value = "当前页码")
            @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
            @ApiParam(value = "每页显示数量")
            @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize
) {
logger.info("分页查询护理计划列表:name={},status={},pageNum={},pageSize={},",name,status, pageNum, pageSize);
        PageResponse<NursingPlanVo>   pageResponse  =nursingPlanService.pageQuer(name,status, pageNum, pageSize);
        return success(pageResponse);
    }


    /**
     * 新增护理计划
     * @param nursingPlanDto
     * @return
     */
    @PostMapping
    @ApiOperation("新增护理计划")
    public ResponseResult add(
            @ApiParam(value = "护理计划数据传输对象")
            @RequestBody NursingPlanDto nursingPlanDto
            ) {
        logger.info("新增护理计划 请求参数：{}",nursingPlanDto);
        nursingPlanService.add(nursingPlanDto);
        return success();
    }
    /**
     * 根据id删除护理计划
     * @param id
     * @return
     */
    @DeleteMapping("/{id}")
    @ApiOperation("根据id删除护理计划")
    public ResponseResult delete(
            @ApiParam(value = "护理计划id")
            @PathVariable Long id
    ) {
        logger.info("根据id删除护理计划 id:{}",id);
        nursingPlanService.delete(id);
        return success();
    }

    /**
     * 启用/禁用护理计划
     * @param id
     * @param status
     * @return
     */
    @PutMapping("/{id}/status/{status}")
    @ApiOperation("启用/禁用")
    public ResponseResult startOrStopStatus(
            @ApiParam(value = "护理计划id")
            @PathVariable Long id,
            @ApiParam(value = "状态（0：禁用，1：启用）")
            @PathVariable Integer status
    ) {
        logger.info("启用/禁用护理计划 id:{} status:{}",id,status);
        nursingPlanService.startOrStopStatus(id,status);
        return success();
    }

    @GetMapping
    @ApiOperation("查询所有护理计划")
    public ResponseResult<List<NursingPlan>> getAll(){
        logger.info("查询所有护理计划");
        List<NursingPlan> nursingPlanList = nursingPlanService.getAll();
        return success(nursingPlanList);

    }


    /**
     * 根据ID查询护理计划
     *
     */
    @GetMapping("/{id}")
    @ApiOperation("根据ID查询")
    public ResponseResult<NursingPlanVo> findId(@PathVariable("id") Long id ){
        logger.info("根据Id查询护理计划:{}",id);
        NursingPlanVo nursingPlanVo = nursingPlanService.findId(id);
        return success(nursingPlanVo );

    }

    /**
     * 编辑护理计划
     * @param nursingPlanDto
     * @return
     */
    @PutMapping("/{id}")
    @ApiOperation("编辑")
    public ResponseResult update(
            @ApiParam(value = "护理计划数据传输对象")
            @RequestBody NursingPlanDto nursingPlanDto
    ) {
        logger.info("编辑护理计划 请求参数：{}",nursingPlanDto);
        nursingPlanService.update(nursingPlanDto);
        return success();
    }

}
